package com.dazhao.animejaphome.home;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.TextView;

import com.dazhao.animejaphome.R;
import com.dazhao.animejaphome.bean.NewsTextBean;
import com.dazhao.animejaphome.httpservice.NewsTextAPI;
import com.squareup.picasso.Picasso;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class NewsDetailsActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news_details);

//        setSupportActionBar(toolbar);

        String jsonUrl=getIntent().getStringExtra("jsonUrl");
        String url=getIntent().getStringExtra("url");

        final TextView textView=(TextView) findViewById(R.id.textView);
        final TextView textView2=(TextView)findViewById(R.id.textView2);
        ImageView imageView =(ImageView)findViewById(R.id.imageView);

        Retrofit retrofit= new Retrofit.Builder()
                .baseUrl("http://114.67.131.62/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        NewsTextAPI service = retrofit.create(NewsTextAPI.class);
        Call<NewsTextBean> newsTextBeanCall =service.repo(jsonUrl);
        newsTextBeanCall.enqueue(new Callback<NewsTextBean>() {
            @Override
            public void onResponse(Call<NewsTextBean> call, Response<NewsTextBean> response) {

                textView.setText(response.body().getTitle());
                textView2.setText(response.body().getText());

            }

            @Override
            public void onFailure(Call<NewsTextBean> call, Throwable t) {

            }
        });

        Picasso .with(this)
                .load(url)
                .into(imageView);


    }

}
